﻿using System;
using System.ComponentModel;
using SharpRomans.Exceptions;

namespace SharpRomans.ParsingRules
{
	[Description("0")]
	internal class FigurableCharacter : IObserver<char>
	{
		private readonly string _literal;

		public FigurableCharacter(string literal)
		{
			_literal = literal;
		}

		private int _characterCounter;
		public void OnNext(char value)
		{
			RomanFigure figure;
			if (!RomanFigure.TryParse(value, out figure))
				throw new ParseException(_literal, _characterCounter);
			_characterCounter++;
		}

		public void OnError(Exception error)
		{
			throw error;
		}

		public void OnCompleted() { }
	}
}
